import React, { useState, useRef } from 'react'
import Child from './Child'

const Index = () => {
    const [num, numSet] = useState(0)
    const numRef = useRef(0)

    console.log('parent render')

    const click = () => {
        // numSet(oldNum => {
        //     console.log(oldNum + 1)
        //     return oldNum + 1
        // })
        
        numRef.current = numRef.current + 1
        console.log('numRef',numRef.current)
        numSet(numRef.current)
    }

    return (
        <div>
            <Child num={num} />
            <button onClick={click}>+1</button>
        </div>
    )
}

export default Index
